import {
  ConnectedSocket,
  MessageBody,
  SubscribeMessage,
  WebSocketGateway,
} from '@nestjs/websockets';
import * as WebSocket from 'ws';
import * as colors from 'colors';

/* 使用 webSocket 网关 */
/* 指定 */
@WebSocketGateway(3536, {
  namespace: 'events',
  transports: ['websocket'],
})
export class WealthGateway {
  @SubscribeMessage('hello sock')
  helloSock(
    @MessageBody() data: any,
    @ConnectedSocket() client: WebSocket,
  ): any {
    console.log('socket', colors.red(data));
    client.send(
      JSON.stringify({
        event: 'tmp',
        data: '这里是个临时信息rustfisher.com',
      }),
    );
    return {
      msg: 'heloo socket',
    };
  }
}
